package com.wc.AlgoOJ_homework.aloj模拟赛.替换字符;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/5/30 23:21
 * @description http://43.138.190.70:8888/p/561?tid=6655c0f9c056ef947a21997d
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010;
    static int[][] tr = new int[N << 2][26];
    static int[] laz = new int[N << 2];
    static char[] s;
    static int m, n;

    public static void main(String[] args) {
        s = (" " + sc.next()).toCharArray();
        n = s.length - 1;
        build(1, 1, n);
        m = sc.nextInt();
        while (m-- > 0) {
            int l = sc.nextInt(), r = sc.nextInt();
            char a = sc.next().charAt(0), b = sc.next().charAt(0);
            modify(1, 1, n, l, r, a - 'a', b - 'a');
        }
        print(1, 1, n);
        out.flush();
    }

    static void print(int u, int l, int r) {
        if (l == r) {
            out.print((char) (tr[u][s[l] - 'a'] + 'a'));
            return;
        }
        pushDown(u, l, r);
        int mid = l + r >> 1;
        print(u << 1, l, mid);
        print(u << 1 | 1, mid + 1, r);
    }

    static void build(int u, int l, int r) {
        for (int i = 0; i < 26; i++) {
            tr[u][i] = i;
        }
        if (l == r) {
            return;
        }
        int mid = l + r >> 1;
        build(u << 1, l, mid);
        build(u << 1 | 1, mid + 1, r);
    }

    static void modify(int u, int l, int r, int ql, int qr, int a, int b) {
        if (l == ql && r == qr) {
            for (int i = 0; i < 26; i++) {
                if (tr[u][i] == a) {
                    tr[u][i] = b;
                }
            }
            laz[u] = 1;
            return;
        }
        pushDown(u, l, r);
        int mid = l + r >> 1;
        if (mid >= qr) modify(u << 1, l, mid, ql, qr, a, b);
        else if (mid < ql) modify(u << 1 | 1, mid + 1, r, ql, qr, a, b);
        else {
            modify(u << 1, l, mid, ql, mid, a, b);
            modify(u << 1 | 1, mid + 1, r, mid + 1, qr, a, b);
        }
    }

    static void pushDown(int u, int l, int r) {
        if (laz[u] == 1) {
            // 转换两次
            for (int i = 0; i < 26; i++) {
                tr[u << 1][i] = tr[u][tr[u << 1][i]];
                tr[u << 1 | 1][i] = tr[u][tr[u << 1 | 1][i]];
            }
            for (int i = 0; i < 26; i++) tr[u][i] = i;
            laz[u << 1] = laz[u << 1 | 1] = 1;
            laz[u] = 0;
        }
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
